<?php
//echo $id;exit;
$question_title = Questions::model()->FindByPk($id)->title;
$quiz_id = Questions::model()->FindByPk($id)->quiz_id;

$quiz_name = Quiz::model()->FindByPk($quiz_id)->title;


if(isset($quiz_name)){
	$this->breadcrumbs=array(
		
		"$quiz_name"=>array('Quiz/admin','qid'=>$quiz_id),
		"$question_title"=>array('Questions/admin','id'=>$quiz_id),
		//'Questions'=>array('admin'),
		'Manage Options',
);}
else {
	$this->breadcrumbs=array(
	
	'Questions'=>array('admin'),
	'Manage',
	);
}
	//Image URL
$delete_path="/eduapp/images/link/delete.png";
$add_more_path="/eduapp/images/link/add_quiz.png";
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'options-form',
	'enableAjaxValidation'=>false,
)); ?>
<?php echo CHtml::beginForm(); ?>
<?php echo '<b>Managing options for <u> '.Questions::model()->findByPk($id)->title.'</u> question</b>'; ?>
<?php if(Yii::app()->user->hasFlash('error')):?>
    <div style="color: red;" class="info">
        <?php echo Yii::app()->user->getFlash('error'); ?>
    </div>
<?php endif; ?>
<?php
Yii::app()->clientScript->registerScript(
   'myHideEffect',
   '$(".info").animate({opacity: 1.0}, 3000).fadeOut("slow");',
   CClientScript::POS_READY
);
?>
<?php if(Yii::app()->user->hasFlash('success')):?>
    <div style="color: green;" class="info">
        <?php echo Yii::app()->user->getFlash('success'); ?>
    </div>
<?php endif; ?>
<?php
Yii::app()->clientScript->registerScript(
   'myHideEffect',
   '$(".info").animate({opacity: 1.0}, 3000).fadeOut("slow");',
   CClientScript::POS_READY
);
?>

<?php //echo '<pre>';print_r($default);exit;
	$count=0;
	
?>
<table>
<tr><th>Id</th><th>Name</th><th>correct answer</th><th>Action</th></tr>
<?php foreach($items as $i=>$item): 
?>
<tr>
<td><?php echo CHtml::activeTextField($item,"[$i]id",array('size'=>1,'disabled' => 'disabled')) ?></td>
<td><?php echo CHtml::activeTextArea($item,"[$i]name"); ?></td>
<td>
<?php 
$newarray=array();
$selected = null;


if($item->correct_option=='yes')
{
	$selected="checked";
	
	 echo CHtml::activeRadioButton($item,"[$i]correct_option",array('checked' =>$selected,"id"=>"[$i]correct_option", "onclick"=>'setoption("['.$i.']correct_option")'));
}
else 
{	
	echo CHtml::activeRadioButton($item,"[$i]correct_option",array("id"=>"[$i]correct_option",'onclick'=>'setoption("['.$i.']correct_option")'));
}?>
</td>
<?php //echo CHtml::link(CHtml::image("$delete_path","Delete",''),array('Options/remove',"id"=>$item->id)) ?>
<td>
<?php echo CHtml::ajaxLink(
	    CHtml::image("$delete_path","Delete",''),          // the link body (it will NOT be HTML-encoded.)
	    Yii::app()->createUrl( 'admin/options/remove/id/'.$item->id ), // the URL for the AJAX request. If empty, it is assumed to be the current URL.
	    array(
	         'success' => "function( data )
                  {
                    window.location.reload();
                  }",
	    	'error' => "function( data )
                  {
                    window.location.reload();
                  }",
	    )
 
); ?>
</td>                    
</tr>

<?php $count++; endforeach; ?>

</table>
 <?php echo CHtml::submitButton('Save'); ?>
<?php // echo CHtml::submitButton('Add More'); ?>
<?php //echo CHtml::link(CHtml::image("$add_more_path"),array('admin/Options/batchUpdate','id'=>$id,'name'=>'true')) ?>


<?php echo CHtml::endForm(); ?>
<?php $this->endWidget(); ?>
</div><!-- form -->


<script type="text/javascript">
function setoption($id)
{
	
	for(var i=0;i<10;i++)
	{
		var name1="["+i+"]correct_option";	

		if(document.getElementById(name1))
			document.getElementById(name1).checked=false;
		
	}
	document.getElementById($id).checked="checked";

}
</script>

